<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">

<mapper namespace="{{packagePath}}.mapper.{{className}}Mapper">

    <!-- 通用查询映射VO结果 -->
    <resultMap id="BaseResultRespVOMap" type="{{packagePath}}.vo.{{className}}RespVO">
        <result column="id" property="id" />
        {{#fields}}
        <result column="{{columnName}}" property="{{propertyName}}" />
        {{/fields}}
    </resultMap>

    <!-- 分页查询 -->
    <select id="pageQuery" resultMap="BaseResultRespVOMap">
        select
        <include refid="Base_Column_RespVO_List"/>
        from
        <include refid="table_name" />
        <where>
            <include refid="common_where" />
        </where>
    </select>

    <!-- 查询list -->
    <select id="queryList" resultMap="BaseResultRespVOMap">
        select
        <include refid="Base_Column_RespVO_List"/>
        from
        <include refid="table_name" />
        <where>
            <include refid="common_where" />
        </where>
    </select>

    <select id="queryById" resultMap="BaseResultRespVOMap">
        select
        <include refid="Base_Column_RespVO_List"/>
        from
        <include refid="table_name" />
        where {{tableName}}.id = #{id}
    </select>

    <!-- 通用查询结果列 -->
    <sql id="Base_Column_RespVO_List">
        id,
        {{#fields}}
        {{columnName}}{{^last}}, {{/last}}
        {{/fields}}
    </sql>

    <!-- 表名 -->
    <sql id="table_name">{{tableName}}</sql>

    <!-- 通用查询条件 -->
    <sql id="common_where">
        <if test="condition.id!=null">
            and {{tableName}}.id = #{condition.id}
        </if>
        {{#fields}}
        <if test="condition.{{propertyName}}!=null {{#isString}}and condition.{{propertyName}}!=''{{/isString}}">
            and {{tableName}}.{{columnName}} = #{condition.{{propertyName}}}
        </if>
        {{/fields}}
    </sql>
</mapper>